﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WeifenLuo.WinFormsUI.Base
{
    public partial class FormSearch : Form
    {
        FormBaseDataGrid mFrmBaseDG;
        int columnIndex;
        string columnName;

        public FormSearch(FormBaseDataGrid aFrmBaseDG)
        {
            InitializeComponent();
            mFrmBaseDG = aFrmBaseDG;
        }

        private void FormSearch_Load(object sender, EventArgs e)
        {
            Point loc;
            loc = Control.MousePosition;
            this.Location = loc;
            txtSearch.Focus();
            columnIndex = mFrmBaseDG.mdbg_dataGrid.SortedColumn.Index;
            columnName = mFrmBaseDG.mdbg_dataGrid.Columns[columnIndex].Name;
            lblColName.Text = mFrmBaseDG.mdbg_dataGrid.Columns[columnIndex].HeaderText; ;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                //((DataSet)mFrmBaseDG.mdbg_dataGrid.DataSource).Tables[0].DefaultView.RowFilter = String.Format("{0} = '{1}'", ((DataSet)mFrmBaseDG.mdbg_dataGrid.DataSource).Tables[0].Columns[columnIndex].ColumnName, txtSearch.Text.Trim());
                mFrmBaseDG.FindNext(txtSearch.Text.Trim(), chkMatchCase.Checked, rdbUp.Checked, mFrmBaseDG.mdbg_dataGrid.SortedColumn.Index, mFrmBaseDG.mdbg_dataGrid.SelectedRows[0].Index);
            }
            catch(Exception ex)
            {
                
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormSearch_FormClosing(object sender, FormClosingEventArgs e)
        {
          
        }

    }
}
